
package com.backsectionmodule.dao;
import com.backsectionmodule.bean.*;
import java.sql.*;
import java.util.*;
import util.*;
public class TbBackSectionDAO {
    private Connection conn = null;
    private PreparedStatement pt = null;
    private ResultSet rs = null;
    private boolean flag = false;
    private String sql = "";
    private TbBackSection tbBackSection=null;
    private List<TbBackSection> tbBackSectionList=null;

    public boolean add(TbBackSection inTbBackSection){
        try{
            
        conn=ConnectDB.getSqlServerConnection();
        sql="insert into Tb_BackSection(BackSectionCode,ProjectCode,BackSectionType,BackSectionSequence,BackSectionAmount,BackSectionCompanyName,BackSectionTime) values(?,?,?,?,?,?,?)";
        pt = conn.prepareStatement(sql);
        
        pt.setString(1,inTbBackSection.getBackSectionCode());
        pt.setString(2,inTbBackSection.getProjectCode());
        pt.setInt(3,inTbBackSection.getBackSectionType());
        pt.setInt(4,inTbBackSection.getBackSectionSequence());
        pt.setDouble(5,inTbBackSection.getBackSectionAmount());
        pt.setString(6,inTbBackSection.getBackSectionCompanyName());
        pt.setString(7,inTbBackSection.getBackSectionTime());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            ConnectDB.closeSqlConnection();
        }
        return flag;
    }
    public boolean del(int inBackSectionId){
        return UtilDAO.del("Tb_BackSection", "BackSectionId", inBackSectionId);
    }
    public boolean edit(TbBackSection inTbBackSection){
        try{
            
        conn=ConnectDB.getSqlServerConnection();
        sql="update Tb_BackSection set  BackSectionCode=?,ProjectCode=?,BackSectionType=?,BackSectionSequence=?,BackSectionAmount=?,BackSectionCompanyName=?,BackSectionTime=? where BackSectionId=?";
        pt = conn.prepareStatement(sql);
        
       
        pt.setString(1,inTbBackSection.getBackSectionCode());
        pt.setString(2,inTbBackSection.getProjectCode());
        pt.setInt(3,inTbBackSection.getBackSectionType());
        pt.setInt(4,inTbBackSection.getBackSectionSequence());
        pt.setDouble(5,inTbBackSection.getBackSectionAmount());
        pt.setString(6,inTbBackSection.getBackSectionCompanyName());
        pt.setString(7,inTbBackSection.getBackSectionTime());
        pt.setInt(8,inTbBackSection.getBackSectionId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            ConnectDB.closeSqlConnection();
        }
        return flag;
    }
    public TbBackSection getTbBackSectionByBackSectionId(int inBackSectionId) {
        tbBackSection=null;
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_BackSection where BackSectionId=? ";
            pt = conn.prepareStatement(sql);
            pt.setInt(1,inBackSectionId);
            rs = pt.executeQuery();
            while (rs.next()) {
                if (tbBackSection == null)tbBackSection = getTbBackSection(rs);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            ConnectDB.closeSqlConnection();
        }
        return tbBackSection;
    }
    public List<TbBackSection> getTbBackSectionAll() {
        tbBackSectionList=new ArrayList<TbBackSection>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_BackSection";
            pt = conn.prepareStatement(sql);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbBackSectionList.add(getTbBackSection(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            ConnectDB.closeSqlConnection();
        }
        return tbBackSectionList;
    }
    public List<TbBackSection> getTbBackSectionAll(VskPage vp) {
        tbBackSectionList=new ArrayList<TbBackSection>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_BackSection";
            vp.setAllCountSql(sql);
            vp.getAllRecordCount(conn, vp.getAllCountSql());
            pt = conn.prepareStatement(vp.processPageSql( "Tb_BackSection", "BackSectionId"));
            rs = pt.executeQuery();
            while (rs.next()) {
                tbBackSectionList.add(getTbBackSection(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            ConnectDB.closeSqlConnection();
        }
        return tbBackSectionList;
    }
    public TbBackSection getTbBackSection(ResultSet rs) throws Exception{
        TbBackSection tbBackSection = new TbBackSection();
        tbBackSection.setBackSectionId(rs.getInt("BackSectionId"));
        tbBackSection.setBackSectionCode(rs.getString("BackSectionCode"));
        tbBackSection.setProjectCode(rs.getString("ProjectCode"));
        tbBackSection.setBackSectionType(rs.getInt("BackSectionType"));
        tbBackSection.setBackSectionSequence(rs.getInt("BackSectionSequence"));
        tbBackSection.setBackSectionAmount(rs.getDouble("BackSectionAmount"));
        tbBackSection.setBackSectionCompanyName(rs.getString("BackSectionCompanyName"));
        tbBackSection.setBackSectionTime(rs.getString("BackSectionTime"));
        tbBackSection.setCreateTime(rs.getString("CreateTime"));
        return tbBackSection;
    }
}
